package ninja.awesome.game;

import ninja.awesome.framework.Game;
import ninja.awesome.framework.Graphics;
import ninja.awesome.framework.Screen;
import ninja.awesome.framework.impl.AndroidGame;
import android.graphics.Color;
import android.graphics.Paint;

public class LoadingScreen extends Screen {
	private static final String TAG = LoadingScreen.class.getSimpleName();

	private static final int SLEEPTIME = 2000;
	private static boolean DEBUG_MODE = false;

	private Thread loadingThread = null;

	public LoadingScreen(Game game) {
		super(game);
	}

	@Override
	public void update(float deltaTime) {
		if (loadingThread == null && !Assets.initialized) {
			loadingThread = new Thread(new Runnable() {

				@Override
				public void run() {
					try {
						Assets.playBgMusic(game);
						Assets.initializeResource((AndroidGame) game);
						if (DEBUG_MODE) {
							game.setScreen(new MainGameScreen(game));
						} else {
							Thread.sleep(SLEEPTIME);
							game.setScreen(new MainMenuScreen(game));
						}
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			});
			loadingThread.start();
		}

	}

	@Override
	public void paint(float deltaTime) {
		Graphics g = game.getGraphics();
		g.clearScreen(Color.BLACK);
		Paint p = new Paint();
		p.setColor(Color.WHITE);
		p.setTextSize(150);
		p.setAntiAlias(true);
		p.setTypeface(Assets.fontFace);
		p.setTypeface(Assets.fontFace);
		g.drawString("Ninja Awesome", 120, 320, p);
		p.setTextSize(50);
		g.drawString("Loading...", 900, 420, p);
	}

	@Override
	public void pause() {

	}

	@Override
	public void resume() {

	}

	@Override
	public void dispose() {

	}

	@Override
	public void backButton() {
	}
}